package com.itheima.jobs;

import com.itheima.entity.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    @Autowired
    private JedisPool jedisPool;

    public void clearImg(){
        //通过比较jedisPool提供的方法sdiff比较两个rides中的存储集合中的数据,找出差集
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);

        //遍历差集
        if(set.size()>0) {
            for (String fileName : set) {
                //删除七牛云中在差集中出现的名字
                QiniuUtils.deleteFileFromQiniu(fileName);
                //删除rides中内存的值
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,fileName);
            }
        }
    }
}
